package love.yuanmeng.guetcoalsystem.service.impl;

/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:lzl
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/10/17 11:25
 */


import love.yuanmeng.guetcoalsystem.mapper.EnterpriseInfoMapper;
import love.yuanmeng.guetcoalsystem.mapper.UserMapper;
import love.yuanmeng.guetcoalsystem.pojo.EnterpriseInfo;
import love.yuanmeng.guetcoalsystem.pojo.User;
import love.yuanmeng.guetcoalsystem.service.UserInfoManageService;
import love.yuanmeng.guetcoalsystem.vo.RegisterVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserInfoManageServiceImpl implements UserInfoManageService {

    @Resource
    UserMapper userInfo;

    @Resource
    EnterpriseInfoMapper enterpriseInfo;

    @Override
    public RegisterVo doService(String userId) {
        User user = userInfo.selectById(Integer.parseInt(userId));
        EnterpriseInfo enterpriseInfo = this.enterpriseInfo.selectById(Integer.parseInt(user.getEnterpriseid()));
        RegisterVo registerVo = new RegisterVo();
        registerVo.setEnterpriseInfo(enterpriseInfo);
        registerVo.setUserInfo(user);
        return registerVo;
    }

    @Override
    public int modifyInfo(RegisterVo registerVo) {
        User user = registerVo.getUserInfo();
        EnterpriseInfo enterprise = registerVo.getEnterpriseInfo();
        if("需求方".equals(user.getStatus())){
            user.setStatus("0");
            enterprise.setEnterpriseType("0");
        }else{
            user.setStatus("1");
            enterprise.setEnterpriseType("1");
        }
        int result = userInfo.updateById(user);
        if(result==0) return 0;
        result=enterpriseInfo.updateById(enterprise);
        return result;
    }
}
